'''
@Project ：hdcms-scripts
@File    ：create_strawberry.py
@IDE     ：PyCharm
@Author  ：朱广杰
@Date    ：2024/12/5 14:59
'''
import json

import jsonpath

from script.api.base_api import BaseCmsv2Api
from common.time_util import get_now_timestamp, get_next_2min_datetime
from common.FILE_PATH import load_yaml_file, BASE_DIR


#  导入课程
class AddScheduleApi(BaseCmsv2Api):
    def __init__(self):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry/schedule'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "activity_tag": "openclass_202202",
            "schedule_desc": "GJ测试",
            "seq_no": 1,
            "online_day": 0
            }

class RelateCourseApi(BaseCmsv2Api):
    def __init__(self, course_id: str, online_day: int):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry/relate_course'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "activity_tag": "openclass_202202",
            "course_id": course_id,
            "online_day": online_day
        }

class GetScheduleApi(BaseCmsv2Api):
    def __init__(self):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry/schedule_list'
        self.method = 'get'
        self.params = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "activity_tag": "openclass_202202"
        }

class AddStrawberry0Api(BaseCmsv2Api):
    def __init__(self, online_day: int): #  berry type 0: 呼应time 1: 投票题 3.课程总结
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry'
        self.method = 'post'
        self.json = {
           "berry_id": 0,
            "title": "GJ测试呼应time无ppt",
            "state": 0,
            "online_day": online_day,
            "berry_type": 0,
            "questions": [
                "A",
                "B",
                "C",
                "D"
            ],
            "option_num": 1,
            "template": "",
            "enable_rate": 0,
            "add_selected_list": [],
            "screen_state": 0,
            "only_sync_msg": 0,
            "related_course_id": "a0d6c6f51a0b5b4eef336ae038affa69",
            "related_course_name": "自动化投屏专用课",
            "start_time": get_next_2min_datetime(),
            "duration": 3,
            "start_page": 0,
            "end_page": 0,
            "prompt_id": 0,
            "publish_live": 1,
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun"
        }

class AddStrawberry1Api(BaseCmsv2Api):
    def __init__(self, online_day: int): #  berry type 0: 呼应time 1: 投票题 3.课程总结
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry'
        self.method = 'post'
        self.json = {
           "berry_id": 0,
            "title": "GJ测试投票题无ppt",
            "state": 0,
            "online_day": online_day,
            "berry_type": 1,
            "questions": [
                "A",
                "B",
                "C",
                "D"
            ],
            "option_num": 1,
            "template": "1.\n2.\n3.",
            "enable_rate": 0,
            "add_selected_list": [],
            "screen_state": 0,
            "only_sync_msg": 0,
            "related_course_id": "a0d6c6f51a0b5b4eef336ae038affa69",
            "related_course_name": "自动化投屏专用课",
            "start_time": get_next_2min_datetime(),
            "duration": 3,
            "start_page": 0,
            "end_page": 0,
            "prompt_id": 0,
            "publish_live": 1,
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun"
        }

class AddStrawberry3Api(BaseCmsv2Api):
    def __init__(self, online_day: int): #  berry type 0: 呼应time 1: 投票题 3.课程总结
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry'
        self.method = 'post'
        self.json = {
            "berry_id": 0,
            "title": "GJ测试课程总结无ppt",
            "state": 0,
            "online_day": online_day,
            "berry_type": 3,
            "questions": [
                "",
                ""
            ],
            "option_num": 1,
            "template": "",
            "enable_rate": 0,
            "add_selected_list": [],
            "screen_state": 0,
            "only_sync_msg": 0,
            "related_course_id": "a0d6c6f51a0b5b4eef336ae038affa69",
            "related_course_name": "自动化投屏专用课",
            "start_time": get_next_2min_datetime(),
            "duration": 3,
            "start_page": 0,
            "end_page": 0,
            "prompt_id": 9,
            "publish_live": 1,
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun"
        }

class AddStrawberryPage0Api(BaseCmsv2Api):
    def __init__(self, online_day: int): #  berry type 0: 呼应time 1: 投票题 3.课程总结
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry'
        self.method = 'post'
        self.json = {
           "berry_id": 0,
            "title": "GJ测试呼应time",
            "state": 0,
            "online_day": online_day,
            "berry_type": 0,
            "questions": [
                "A",
                "B",
                "C",
                "D"
            ],
            "option_num": 1,
            "template": "",
            "enable_rate": 0,
            "add_selected_list": [],
            "screen_state": 0,
            "only_sync_msg": 0,
            "related_course_id": "a0d6c6f51a0b5b4eef336ae038affa69",
            "related_course_name": "自动化投屏专用课",
            "start_time": get_next_2min_datetime(),
            "duration": 3,
            "start_page": 3,
            "end_page": 10,
            "prompt_id": 0,
            "publish_live": 1,
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun"
        }

class AddStrawberryPage1Api(BaseCmsv2Api):
    def __init__(self, online_day: int): #  berry type 0: 呼应time 1: 投票题 3.课程总结
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry'
        self.method = 'post'
        self.json = {
           "berry_id": 0,
            "title": "GJ测试投票题",
            "state": 0,
            "online_day": online_day,
            "berry_type": 1,
            "questions": [
                "A",
                "B",
                "C",
                "D"
            ],
            "option_num": 1,
            "template": "1.\n2.\n3.",
            "enable_rate": 0,
            "add_selected_list": [],
            "screen_state": 0,
            "only_sync_msg": 0,
            "related_course_id": "a0d6c6f51a0b5b4eef336ae038affa69",
            "related_course_name": "自动化投屏专用课",
            "start_time": get_next_2min_datetime(),
            "duration": 3,
            "start_page": 11,
            "end_page": 15,
            "prompt_id": 0,
            "publish_live": 1,
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun"
        }

class AddStrawberryPage3Api(BaseCmsv2Api):
    def __init__(self, online_day: int): #  berry type 0: 呼应time 1: 投票题 3.课程总结
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/strawberry'
        self.method = 'post'
        self.json = {
            "berry_id": 0,
            "title": "GJ测试课程总结",
            "state": 0,
            "online_day": online_day,
            "berry_type": 3,
            "questions": [
                "",
                ""
            ],
            "option_num": 1,
            "template": "",
            "enable_rate": 0,
            "add_selected_list": [],
            "screen_state": 0,
            "only_sync_msg": 0,
            "related_course_id": "a0d6c6f51a0b5b4eef336ae038affa69",
            "related_course_name": "自动化投屏专用课",
            "start_time": get_next_2min_datetime(),
            "duration": 3,
            "start_page": 25,
            "end_page": 30,
            "prompt_id": 9,
            "publish_live": 1,
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun"
        }
if __name__ == '__main__':
    AddScheduleApi().send()
    resp = GetScheduleApi().send()
    online_day = course_id = jsonpath.jsonpath(resp.json(), '$..online_day')[0]
    print(online_day)
    RelateCourseApi(online_day=online_day, course_id='a0d6c6f51a0b5b4eef336ae038affa69').send()

    AddStrawberryPage0Api(online_day).send()
    AddStrawberryPage1Api(online_day).send()
    AddStrawberryPage3Api(online_day).send()
    AddStrawberry0Api(online_day).send()
    AddStrawberry1Api(online_day).send()
    AddStrawberry3Api(online_day).send()
